<pre>

// The following is the code portion of query.jsp

FormattedDataSet fds=new FormattedDataSet();
// Load db driver to be monitored. Although the example uses HSQLDB, any JDBC Connection will do.
Class.forName("org.hsqldb.jdbcDriver");

// monitor table accesses.  Accesses to these tables will show up in the JAMon report
List tables=new ArrayList();
tables.add("SYSTEM_TYPEINFO");
tables.add("SYSTEM_TABLES");
MonProxyFactory.setMatchStrings(tables);
  
// Connect to the database and monitor the returned Connection.  That is all you have to do!!!
// All SQL, Exceptions and method calls on JDBC interfaces will now be monitored!
Connection conn = MonProxyFactory.monitor(DriverManager.getConnection("jdbc:hsqldb:.",  "sa", ""));
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from SYSTEM_TYPEINFO where LOCAL_TYPE_NAME IN ('INTEGER', 'DECIMAL', 'TINYINT') order by 1 desc"); 	  


// The formattedDataSet is another API of mine that renders TabularData among other things.        
String html="";
html=fds.getFormattedDataSet(new ResultSetConverter(rs), "htmlTable");                                       
rs.close();
st.close();

// Monitor the PreparedStatement.  Note the SQL Detail report will show how many times the PreparedStatement 
// was reused.
PreparedStatement ps=conn.prepareStatement("select * from SYSTEM_TYPEINFO where LOCAL_TYPE_NAME=?");
ps.setString(1, "INTEGER");

rs = ps.executeQuery();
rs = ps.executeQuery();
rs = ps.executeQuery();
rs = ps.executeQuery();
rs = ps.executeQuery();
rs = ps.executeQuery();
rs = ps.executeQuery();
rs = ps.executeQuery();
rs = ps.executeQuery();
rs = ps.executeQuery();
rs = ps.executeQuery();

// create html for the last resultSet only
String html1="";
html1=fds.getFormattedDataSet(new ResultSetConverter(rs), "htmlTable");      	  


// Run and Monitor another couple queries
st=conn.createStatement();
rs=st.executeQuery("select * from SYSTEM_TABLES"); 
String html2="";
html2=fds.getFormattedDataSet(new ResultSetConverter(rs), "htmlTable");      	  

rs=st.executeQuery("select * from SYSTEM_USERS"); 
String html3="";
html3=fds.getFormattedDataSet(new ResultSetConverter(rs), "htmlTable");    

// Throw an exception and show that it is also monitored in JAMonAdmin.jsp and exceptions.jsp
// Note also even though the catch block is empty it will show up in these pages.
try { 
 // get a query to throw an Exception.  If enabled will show in jamon report and sql details.
 st.executeQuery("select * from i_do_not_exist");  

} catch (Exception e) {} 
 	  
                            

conn.close();

// Show that that MonProxy also works with ANY interface.  In this case an inner class is used.
MyInterface myObj=(MyInterface) MonProxyFactory.monitor(new MyObject());

// method calls will show in the jamon report
myObj.myOpen();
myObj.myClose(); 


//**** Interface and implementing class

  // inteface and class to show interface monitoring work on a custom class.
  public interface MyInterface {
     public int myOpen();
     public int myClose();
    
  }


  private static class MyObject implements MyInterface {
     public int myOpen(){
        return 1;
     }

     public int myClose(){
        return 1;
     }


  } 

</pre>

